package cn.tedu.ivos2.vehiclerepair.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.vehiclerepair.pojo.dto.VehicleRepairParam;
import cn.tedu.ivos2.vehiclerepair.pojo.dto.VehicleRepairQuery;
import cn.tedu.ivos2.vehiclerepair.pojo.vo.VehicleRepairVO;
import cn.tedu.ivos2.vehiclerepair.service.VehicleRepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/repair/")
public class VehicleRepairController {
    @Autowired
    private VehicleRepairService vehicleRepairService;

    @GetMapping("select")
    public JsonResult selectRepair(VehicleRepairQuery vehicleRepairQuery){
        log.debug("C1-查询维修参数:{}",vehicleRepairQuery);
        List<VehicleRepairVO> vehicleRepairVOList=vehicleRepairService.select(vehicleRepairQuery);
        log.debug("C1-查询结果:{}",vehicleRepairVOList);
        return JsonResult.ok(vehicleRepairVOList);
    }
    @DeleteMapping("deleteRepair/{id}")
    public JsonResult deleteRepair(@PathVariable Long id){
        log.debug("C2-删除id:{}",id);
        vehicleRepairService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("save")
    public JsonResult save(VehicleRepairParam vehicleRepairParam){
        log.debug("C3-新增/保存参数:{}",vehicleRepairParam);
        vehicleRepairService.save(vehicleRepairParam);
        return JsonResult.ok();
    }
    @GetMapping("selectById")
    public JsonResult selectById(Long id){
        log.debug("C4-查询维修单id:{}",id);
        VehicleRepairVO vehicleRepairVO=vehicleRepairService.selectById(id);
        log.debug("C4-返回结果:{}",vehicleRepairVO);
        return JsonResult.ok(vehicleRepairVO);
    }
}
